export function getSetting(auth, onSuccess, onFail) {
  mpvue.getSetting({
    success(res) {
      // authSetting: 用户授权结果(是否包含对应权限)
      if (res.authSetting[`scope.${auth}`]) {
        onSuccess(res)
      } else {
        onFail(res)
      }
    },
    fail(res) {
    }
  })
}
export function getUserInfo(onSuccess, onFail) {
  mpvue.getUserInfo({
    success(res) {
      console.log('res')
      const { userInfo } = res
      if (userInfo) {
        onSuccess(userInfo)
      } else {
        onFail(res)
      }
    },
    fail(res) {
      console.log('res') // 直接抛出异常
    }
  })
}
export function setStorageSync(key, data) {
  mpvue.setStorageSync(key, data)
}

export function getStorageSync(key) {
  return mpvue.getStorageSync(key)
}
export function getUserOpenId(callback, userInfo) {
  mpvue.login({
    success(res) {
      if (res.code) {
        const {code} = res
        // console.log('code' + code)
        getOpenId(code).then(response => {
          // console.log(response)
          const { data: { data: { openid } } } = response
          setStorageSync('openId', openid)
          callback && callback(openid)
          // console.log('openid:' + openid)
        }).catch(err => {
          console.log(err) // 直接抛出异常
        })
      } else {
        console.log(res) // 直接抛出异常
      }
    },
    fail(res) {
      console.log(res) // 直接抛出异常
    }
  })
}
export function showLoading(title) {
  mpvue.showLoading({
    title,
    mask: true
  })
}

export function hideLoading() {
  mpvue.hideLoading({)
}


